Skip to content

fix: narrow exceptions in get_speckit_version() from Exception to specific types - #3917

Open
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/assets-narrow-exception-v2
Open

fix: narrow exceptions in get_speckit_version() from Exception to specific types#3917
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/assets-narrow-exception-v2

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Problem

Outer catch narrowed to PackageNotFoundError. Inner catch narrowed to (OSError, ValueError, KeyError) for file/parse errors.

Fix

Narrowed both exception handlers to specific types.

Testing

  • Verified version is returned correctly
  • Verified fallback to pyproject.toml works

…cific types

Outer catch narrowed to PackageNotFoundError (the only expected
failure from importlib.metadata.version). Inner catch narrowed to
(OSError, ValueError, KeyError) for file/parse errors.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Narrows version-resolution exception handling to expected metadata, file, and TOML parsing failures.

Changes:

  • Handles missing package metadata explicitly.
  • Limits pyproject fallback errors to specific exception types.
Show a summary per file
File Description
src/specify_cli/_assets.py Narrows exceptions in get_speckit_version().

Review details

Tip

Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Balanced

except Exception:
# Intentionally ignore any errors while reading/parsing pyproject.toml.
# If this lookup fails for any reason, we fall back to returning "unknown" below.
except (OSError, ValueError, KeyError):
try:
return importlib.metadata.version("specify-cli")
except Exception:
except importlib.metadata.PackageNotFoundError:

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants